<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Orders_model extends My_Model
{
   
    public function __construct()
    {
        parent::__construct();
        $this->model_name="pyapl account report";
        $this->tablename="paypal_orders";   
    }

    public function check_exist($siteid,$orderid)
    {
        $where=["siteid"=>$siteid,"orderid"=>$orderid];
        return $this->get_item_by_where($where);
    }

    public function getpage($siteid,$page,$pagesize,$key="",$state=0,$timelimit=[]){
        
        $where ="1=1";

        if($pagesize>0)
        {
            $this->pagesize=$pagesize;
        }
        
        if($siteid>0)
        {
            $where.=" and siteid=".$siteid;      
        }

        $url=uri_string();

        if($state>0)
        {
            $where.=" and status=".$state;
        }

        if($timelimit && isset($timelimit["start"]) && isset($timelimit["end"]))
        {
            $where.=" and addtime between '".$timelimit["start"]." 00:00:00' and '".$timelimit["end"]." 23:59:59'";
        }
        
      
        if($key)
        {
            $skey=[
                "address"=>$key,
                "realname"=>$key,
                "products"=>$key,
                "postcode"=>$key,
            ];
        }
        else
        {
            $skey="";
        }
        return $this->get_items_by_page($where,$page,$url,"id desc",[],$skey);                
    }


    public function create($data){
        if(!isset($data["addtime"])){
            $data["addtime"]=date("Y-m-d H:i:s");
        }
       
        return $this->add_item($data);       
    }

    public function update($id,$data){

        if(is_array($id))
        {
            $where="id in (".implode(",",$id).")";
           
        }else{
            $where=array("id"=>$id);
           
        }
        return $this->update_item($where,$data);

    }

   
}
